﻿#pragma once
#pragma execution_character_set("utf-8")
// 本文件为utf-8 编码格式

#ifndef __GD__GDShareView__
#define __GD__GDShareView__


#include "../CommonHttpManager.h"
#include "../GdDefine.h"

class GDShareView :
	public CAView
{

public:
	static GDShareView* createWithFrame(const CCRect& rect, bool closeToHidden=true);
	static GDShareView* createWithCenter(const CCRect& rect, bool closeToHidden = true);

	virtual ~GDShareView();

	void onCloseBtnClick(CrossApp::CAControl *control, CrossApp::CCPoint point);
	void onShareItemBtnClick(CrossApp::CAControl *control, CrossApp::CCPoint point);
	/* 设置要分享的内容 */
	void setShareInfo(std::string title, const std::string cnt, const std::string description, const std::string url = "", const std::string imageUrl = "", const std::string goodsId = "0", map<int, string> titleMap = map<int, string>(), map<int, string> cntMap = map<int, string>());
	/* 将url转为短链 */
	void processShortUrl();
	CC_SYNTHESIZE(std::string, pid, Pid);
	CC_SYNTHESIZE(std::string, title, Title);
	CC_SYNTHESIZE(std::string, cnt, Cnt);
	CC_SYNTHESIZE(std::string, description, Description);
	CC_SYNTHESIZE(std::string, url, Url);
	CC_SYNTHESIZE(std::string, imageUrl, ImageUrl);
	CC_SYNTHESIZE(std::string, goodsId, GoodsId);
public:
	void onProcessShortUrlFinish(const HttpResponseStatus& status, const CSJson::Value& json);
protected:
	CAView* createShareItemView();
private:
	GDShareView(bool closeToHidden = true);
	void initView();
	void initSharePlatform();
	CAView* createShareItemView(GDSharePlatform &sharePlatform, int itemWidth, int itemHeight);
private:
	CAView *mainPanel; // 主面板
	CAView *mainNode; // 主节点
	CAView *closeNode; // 关闭节点
	bool closeToHidden;

	map<int, string> titleMap;
	map<int, string> cntMap;
};

/* 全局变量 */
extern GDShareView* GD_SHARE_VIEW;

#endif /* defined(__HelloCpp__ViewController__) */